package com.android.mmchat;

import com.android.mmchat.common.EActivity;
import com.android.mmchat.unit.coupon.CouponActivity;

import android.app.Activity;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;

/**
 * @author 李建国
 * @date 2011-06-17
 * 
 * @author 李建国
 * @date 2011-06-18
 */
public class StartActivity extends TabActivity {
    /** Called when the activity is first created. */
	TabHost myTabHost;
	
	public  String Tag_1 = "coupon";
	public  String Tag_2 = "discount";
	public  String Tag_3 = "collect";
	public  String Tag_4 = "more";
	String Name_1 = "", Name_2 = "", Name_3 = "",Name_4 = "";
	Drawable d1, d2, d3, d4;
	TabHost.TabSpec tab1, tab2, tab3, tab4;
	
	/**测试的TextView*/
    private TextView tv_test;
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_content);
        Init();
    }
    /**绑定UI控件，并作一些初始化处理*/
    private void Init(){
    	Name_1 = getResources().getString(R.string.app_name);
		Name_2= getResources().getString(R.string.app_name);
		Name_3= getResources().getString(R.string.app_name);
		Name_4= getResources().getString(R.string.app_name);
		
		d1 = getResources().getDrawable(R.drawable.icon);
		d2 = getResources().getDrawable(R.drawable.icon);
		d3 = getResources().getDrawable(R.drawable.icon);
		d4 = getResources().getDrawable(R.drawable.icon);
		
		myTabHost = (TabHost) StartActivity.this.findViewById(android.R.id.tabhost);
		LinearLayout ll = (LinearLayout) myTabHost.getChildAt(0);
		TabWidget tw = (TabWidget) ll.getChildAt(1);
	
		RelativeLayout tabIndicator1 = (RelativeLayout) LayoutInflater.from(StartActivity.this).inflate(R.layout.tab_indicator, tw, false);
		ImageView iv1=(ImageView) tabIndicator1.getChildAt(0);
		TextView tvTab1 = (TextView) tabIndicator1.getChildAt(1);
		tvTab1.setText(Name_1);
		iv1.setBackgroundDrawable(d1);
		
		RelativeLayout tabIndicator2 = (RelativeLayout) LayoutInflater.from(StartActivity.this).inflate(R.layout.tab_indicator, tw, false);
		ImageView iv2=(ImageView) tabIndicator2.getChildAt(0);
		TextView tvTab2 = (TextView) tabIndicator2.getChildAt(1);
		tvTab2.setText(Name_2);
		iv2.setBackgroundDrawable(d2);
		
		RelativeLayout tabIndicator3 = (RelativeLayout) LayoutInflater.from(StartActivity.this).inflate(R.layout.tab_indicator, tw, false);
		ImageView iv3=(ImageView) tabIndicator3.getChildAt(0);
		TextView tvTab3 = (TextView) tabIndicator3.getChildAt(1);
		tvTab3.setText(Name_3);
		iv3.setBackgroundDrawable(d3);
		
		RelativeLayout tabIndicator4 = (RelativeLayout) LayoutInflater.from(StartActivity.this).inflate(R.layout.tab_indicator, tw, false);
		ImageView iv4=(ImageView) tabIndicator4.getChildAt(0);
		TextView tvTab4 = (TextView) tabIndicator4.getChildAt(1);
		tvTab4.setText(Name_4);
		iv4.setBackgroundDrawable(d4);

		Intent mainpage = new Intent(StartActivity.this,CouponActivity.class);
		Intent coupon = new Intent(StartActivity.this,CouponActivity.class);
		Intent friends = new Intent(StartActivity.this,CouponActivity.class);
		Intent life = new Intent(StartActivity.this,CouponActivity.class);
		
		tab1 = myTabHost.newTabSpec("tab1").setIndicator(tabIndicator1).setContent(mainpage);
		tab2 = myTabHost.newTabSpec("tab2").setIndicator(tabIndicator2).setContent(coupon);
		tab3 = myTabHost.newTabSpec("tab3").setIndicator(tabIndicator3).setContent(friends);
		tab4 = myTabHost.newTabSpec("tab4").setIndicator(tabIndicator4).setContent(life);	

		myTabHost.addTab(tab1);
		myTabHost.addTab(tab2);
		myTabHost.addTab(tab3);	
		myTabHost.addTab(tab4);
    }//end Init
    /**处理控件的点击事件*/
    private View.OnClickListener onClick(){
    	return new View.OnClickListener() {		
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				switch(v.getId()){
				
				}
			}
		};
    }//end onClick 
    
    
    Handler handelr=new Handler(){
    	public void handleMessage(Message msg){
    		switch(msg.arg1){
    		case 1:
    			break;
    		}
    	}
    };
}